<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title>后台管理系统</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="keywords" content="后台管理系统">
    <meta name="description" content="">
    <link rel="shortcut icon" href="/img/favicon.ico">

    <link rel="stylesheet" href="/plugins/layui_v2/css/layui.css">

    <link rel="stylesheet" href="/plugins/tree/tree.css" type="text/css">
    <link rel="stylesheet" type="text/css" href="http://at.alicdn.com/t/font_9h680jcse4620529.css">


    <script src="/plugins/layui_v2/layui.js"></script>
    <script type="text/javascript" src="/js/jquery-1.8.3.js"></script>
    <script type="text/javascript" src="/plugins/tree/tree.min.js" ></script>
    <script type="text/javascript" src="/plugins/tree/extend.tree.js" ></script>


</head>
<body style="font-size:12px;">
<fieldset class="layui-elem-field">
    <legend  style="font-size: 12px;color:#FF5722;">请选择父级菜单</legend>
    <div class="layui-field-box" style="height: 220px; overflow: auto;">
        <ul id="menuTree"></ul>
    </div>
</fieldset>
<div class="layui-form-item" style="text-align: center;">
    <button class="layui-btn" id="save">保存</button>
    <button type="layui-btn" id="cancle" class="layui-btn layui-btn-primary">取消</button>
</div>

<script type="text/javascript">
    var menuTree;
    layui.config({
        base : "/js/"
    }).use(['tree', 'layer','form','common'], function() {
        var $ = layui.$,
            tree = layui.tree;
            form = layui.form;
            common = layui.common;
            layer = parent.layer === undefined ? layui.layer : parent.layer;


        var nodes;
        $.ajax({
            url : '/sys/menu/parentMenuAjax',
            type : 'post',
            data : {},
            async: true,
            success : function(data) {
                if(data != null ){
                    console.log(data);
                    nodes = data;
                    layui.tree({
                        elem: '#menuTree',
                        nodes: nodes,
                        click: function(node){
                            console.log(node.name); //node即为当前点击的节点数据
                            var parent$ = window.parent.layui.jquery;
                            parent$("#parentName").val(node.name);
                            parent$("#parentId").val(node.id);
                        }
                    });
                }else{
                    common.cmsLayErrorMsg(data);
                }
            },error:function(data){
                common.cmsLayErrorMsg("");
            }
        });

        /**角色菜单信息保存*/
        $("#save").click(function(){
            //角色Id

            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            parent.layer.close(index); //再执行关闭

        });

        //取消
        $("#cancle").click(function(){
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            parent.layer.close(index); //再执行关闭
        });
    });




</script>
</body>
</html>